﻿package mortal.game.view.heroArena.view
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.control.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.arena.data.*;
    import mortal.game.view.common.*;
    import mortal.game.view.heroArena.util.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.vip.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class HeroArenaPanelBase extends GSprite
    {
        protected var _goldTicket:GTextFiled;
        protected var _convertLink:GButton;
        protected var _myArenaMoney:GTextFiled;
        protected var _vipOpenTips:VipOpenTipsPanel;
        protected var _splitLine:ScaleBitmap;
        protected var _arenaMoneySpr:GSprite;
        protected var _introduce:GTextFiled;
        protected var _introduceSpr:GSprite;
        protected var _rewardArr:Array;

        public function HeroArenaPanelBase()
        {
            this._rewardArr = [];
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._introduceSpr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._introduceSpr);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41551), 19, 450, 78, 20, this._introduceSpr, GlobalStyle.textFormatHuang));
            this._introduce = UIFactory.gTextField(Language.getString(41552), 19, 450 + 23, 269 + 5, 50, this._introduceSpr, GlobalStyle.textFormatHuang.setSize(13));
            this._introduce.wordWrap = true;
            this._introduce.multiline = true;
            this._introduceSpr.visible = false;
            this._splitLine = UIFactory.bg(14 - 23, 450 + 23 + 44, 273 + 46 - 13, 2, this, ImagesConst.SplitLine);
            this.pushUIToDisposeVec(UIFactory.bg(14 - 23, 561 - 5, 273 + 46 - 13, 2, this, ImagesConst.SplitLine));
            this._arenaMoneySpr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._arenaMoneySpr);
            this._myArenaMoney = UIFactory.gTextField("", 25 + 36 - 17, 527 + 7, 108, 25, this._arenaMoneySpr, GlobalStyle.textFormatHuang2.setSize(13));
            this._goldTicket = UIFactory.gTextField("", 109 + 36, 527 + 7, 50 + 10, 25, this._arenaMoneySpr, GlobalStyle.textFormatHuang2.setSize(13));
            this._convertLink = UIFactory.gButton(Language.getString(41553), 153 + 36, 527 + 7, 65, 20, this._arenaMoneySpr, "GreenLinkButton");
            this._convertLink.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.VipTipBg_Mid, 15 + 9, 442 + 125 - 3 - 9, this));
            this._vipOpenTips = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            this._vipOpenTips.valueType = VipOpenTipsPanel.numberValue;
            var _loc_1:* = Cache.instance.vip.level;
            var _loc_2:* = VipUtil.getVipMinLevelByType(EVipRecordType._EVipRecordTypeArenaMoney);
            if (_loc_1 < _loc_2)
            {
                this._vipOpenTips.resetLevelTextPos(29 + 3, 1, 29 + 3, 1);
                this._vipOpenTips.resetValueTextPos(96 + 91, 1, 96 + 92, 1);
                this._vipOpenTips.move(9 - 4 + 20, 442 + 125 - 4);
            }
            else
            {
                this._vipOpenTips.resetLevelTextPos(29 + 3, 1, 29 + 3, 1);
                this._vipOpenTips.resetValueTextPos(96 + 91, 1, 96 + 92, 1);
                this._vipOpenTips.move(9 - 4 + 20, 442 + 125 - 4);
            }
            this.addChild(this._vipOpenTips);
            this._vipOpenTips.bgUrl = "";
            this._vipOpenTips.resetTipsTextPos(0, 0, 0, 0);
            this._vipOpenTips.vipType = EVipRecordType._EVipRecordTypeArenaMoney * 10;
            this.createRewardPart();
            this.initArenaMoney();
            this.addListeners();
            return;
        }// end function

        private function initArenaMoney() : void
        {
            var _loc_1:* = HeroArenaUtil.getArenaMoneyByLevel(HeroArenaController.HeroArenaLevel);
            this._myArenaMoney.text = Language.getStringByParam(41554, _loc_1.moneyName);
            this._goldTicket.text = _loc_1.moneyNum + "";
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.HeroArenaGoldUpdate, this.onArenaGoldUpdate);
            NetDispatcher.addCmdListener(ServerCommand.HeroArenaUpdateRewardInfo, this.onUpdateRewardInfo);
            NetDispatcher.addCmdListener(ServerCommand.HeroArenaUpdateArenaLevel, this.onLevelUpdateHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.HeroArenaGoldUpdate, this.onArenaGoldUpdate);
            NetDispatcher.removeCmdListener(ServerCommand.HeroArenaUpdateRewardInfo, this.onUpdateRewardInfo);
            NetDispatcher.removeCmdListener(ServerCommand.HeroArenaUpdateArenaLevel, this.onLevelUpdateHandler);
            return;
        }// end function

        private function createRewardPart() : void
        {
            var _loc_1:int = 0;
            var _loc_2:HeroArenaRewardTakeSpr = null;
            _loc_1 = 0;
            while (_loc_1 < 3)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(HeroArenaRewardTakeSpr);
                _loc_2.x = 291 + 204 * _loc_1;
                _loc_2.y = 447 - 8;
                this.addChild(_loc_2);
                this._rewardArr.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_2.index = _loc_1;
                _loc_1++;
            }
            this.updateRewardInfo();
            return;
        }// end function

        private function updateRewardInfo() : void
        {
            var _loc_2:int = 0;
            var _loc_3:SArenaPlayerReward = null;
            var _loc_1:* = Cache.instance.heroArena.playerRewardDic;
            for each (_loc_3 in _loc_1)
            {
                
                this._rewardArr[_loc_2].data = _loc_3;
                _loc_2++;
                if (_loc_2 >= 3)
                {
                    return;
                }
            }
            if (_loc_2 < 3)
            {
                while (_loc_2 < this._rewardArr.length)
                {
                    
                    this._rewardArr[_loc_2].data = null;
                    _loc_2++;
                }
            }
            return;
        }// end function

        private function onLinkClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = HeroArenaUtil.getArenaMoneyByLevel(HeroArenaController.HeroArenaLevel).shopIndex;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallChangeTabIndex, [ShopUtil.ShopTabArena2v2, _loc_2]));
            return;
        }// end function

        private function onArenaGoldUpdate(param1:SMoney) : void
        {
            this.initArenaMoney();
            return;
        }// end function

        private function onUpdateRewardInfo(param1:Object) : void
        {
            this.updateRewardInfo();
            return;
        }// end function

        private function onLevelUpdateHandler(param1:Object) : void
        {
            this.initArenaMoney();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._goldTicket.dispose();
            this._goldTicket = null;
            this._convertLink.dispose();
            this._convertLink = null;
            this._myArenaMoney.dispose();
            this._myArenaMoney = null;
            this._vipOpenTips.dispose();
            this._vipOpenTips = null;
            this._splitLine.dispose();
            this._splitLine = null;
            this._arenaMoneySpr.dispose();
            this._arenaMoneySpr = null;
            this._introduce.dispose();
            this._introduce = null;
            this._introduceSpr.dispose();
            this._introduceSpr = null;
            this._rewardArr.length = 0;
            this.removeListeners();
            return;
        }// end function

    }
}
